<?php
include('../includes/common.php');
if ($islogin != 1) {
	exit('<script language=\'javascript\'>window.location.href=\'./login.php\';</script>');
}
$mod = isset($_GET['mod']) ? $_GET['mod'] : null;
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>网站配置</title>
    <link href="//cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <link href="//cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="../static/admin/css/inter.css">
    <script src="//cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script>
    <script src="//cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="col-xs-12 col-sm-10 col-lg-8 center-block" style="float: none;padding-top:20px">

        <?php
        if ($mod == 'set_logo') {
            ?>
            <div class="block">
                <div class="block-title">
                    <h3 class="panel-title">更改首页LOGO</h3>
                </div>
                <div class="">
                    <form action="set2.php?mod=up_logo" method="post" class="form-horizontal" role="form" enctype="multipart/form-data">
                        <input type="file" name="file">
                        <br>
                        <button class="btn btn-primary btn-block">提交</button>
                    </form>
                    <br>
                    <p>现在的logo：</p>
                    <img src="../static/picture/logo.png?<?php echo $match ?>" class="img-responsive" alt="">
                </div>
            </div>
        <?php
        } elseif ($mod == 'up_logo') {
            ?>
            <?php
                $file = $_FILES['file'];
                if (!is_uploaded_file($file['tmp_name'])) {
                    showmsg('上传失败,文件非法!', 3);
                }
                if (!in_array($file['type'], array('image/jpeg', 'image/gif', 'image/png'))) {
                    showmsg('上传失败，图片格式有误!', 3);
                }
                $uploadPath = '../static/picture/';
                $uploadUrl = '../static/picture/';
                if (!is_dir($uploadPath)) {
                    mkdir($uploadPath . $fileDir, 0777, true);
                }
                $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
                $bg = 'logo.png';
                $imgPath = $uploadPath . $bg;
                if (!move_uploaded_file($file['tmp_name'], $imgPath)) {
                    showmsg('服务器繁忙', 4);
                } else {
                    showmsg('上传成功！<br/><a href="set.php">>>返回系统设置</a>', 1);
                }
            } elseif ($mod == 'defend') {
                ?>
            <div class="block">
                <div class="block-title">
                    <h3 class="panel-title">防CC模块设置</h3>
                </div>
                <div class="">
                    <form action="./set2.php?mod=defend_n" method="post" class="form-horizontal" role="form">
                        <input type="hidden" name="do" value="submit" />
                        <div class="form-group">
                            <label class="col-sm-2 control-label">CC防护等级</label>
                            <div class="col-sm-10"><select class="form-control" name="defendid">
                                    <option value="0" <?php if (CC_Defender == 0) { ?>selected<?php } ?>>关闭</option>
                                    <option value="1" <?php if (CC_Defender == 1) { ?>selected<?php } ?>>低(推荐)</option>
                                    <option value="2" <?php if (CC_Defender == 2) { ?>selected<?php } ?>>中</option>
                                    <option value="3" <?php if (CC_Defender == 3) { ?>selected<?php } ?>>高</option>
                                </select></div>
                        </div><br />
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10"><input type="submit" name="submit" value="修改" class="btn btn-primary form-control" /><br />
                            </div>
                        </div>
                    </form>
                </div>
                <div class="panel-footer">
                    <span class="glyphicon glyphicon-info-sign"></span>CC防护说明<br />
                    高：全局使用防CC，会影响网站APP和对接软件的正常使用<br />
                    中：会影响搜索引擎的收录，建议仅在正在受到CC攻击且防御不佳时开启<br />
                    低：用户首次访问进行验证（推荐）<br />
                </div>
            </div>
        <?php
        } elseif ($mod == 'defend_n' && $_POST['do'] == 'submit') {
            $defendid = $_POST['defendid'];
            $file = "<?php\r\n//防CC模块设置\r\ndefine('CC_Defender', " . $defendid . ");\r\n?>";
            file_put_contents(SYSTEM_ROOT . 'base.php', $file);
            showmsg('修改成功！', 1);
        }
        ?>
    </div>

</body>

</html>